package com.ash.interceptor;

import com.ash.domain.User;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/3/30 21:29
 * @file : project06.com.ash.interceptor.AdminInterceptor.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
public class AdminInterceptor implements HandlerInterceptor {
    /*admin登录拦截*/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user =(User)session.getAttribute("user");
        return user.getRid()==1;
    }
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
